<!--  -->
<template>
  <div class="upload-images">
    <div v-for="(item, index) in photos" :key="index">
      <div class="icon-po">
        <img class="image" :src="item.src" />
        <div class="icon-close" @click="imgclose(index)">×</div>
      </div>
    </div>
    
    <ul class="photo_box" v-if="photos.length != count" @click="chooseImg">
      <li>
        <i class="iconicon-tianjia iconfont"></i>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    photos: {
      type: Array,
      default: () => []
    },
    count: {
      type: Number,
      default: 0
    }
  },
  methods: {
    chooseImg() {
      this.$emit("open", "");
    },
    imgclose(e) {
      this.$emit("close", e);
    },
    uploadImage(index) {
      let _this = this;
      var item = _this.paths[index];
      window.gsmdp.uploadFile({
        key: {
          url: config.baseUrl + "/app/alarm/uploadDealFile",
          filePath: item.filePath,
          name: "file"
        },
        taskFail(err) {
          _this.$LoadView.hideLoading();
          _this.$LoadView.showToast(err + "上传出错");
        },
        taskComplete(result) {
          let response = JSON.parse(result.responseStr);
          _this.ids.push(response.data);
          if (_this.ids.length == _this.paths.length) {
            _this.detalrequest();
          } else {
            _this.uploadImage(index + 1);
          }
        }
      });
    },
  }
};
</script>
<style lang="stylus" scope>
.upload-images {
  padding: 0 0.1rem;
  display: grid;
  grid-template-columns: 33% 33% 33%;
  grid-template-rows: 33% 33% 33%;
  grid-row-gap: 0.5rem;
  grid-column-gap: 0.1rem;
  align-items: center;
  justify-content: center;

  .image {
    width: 1.78rem;
    height: 1.78rem;
  }

  .icon-po {
    flex: 1;
    position: relative;
  }

  .icon-close {
    position: absolute;
    left: 1.7rem;
    top: -8px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: red;
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
  }

  .photo_box {
    display: flex;
    flex-direction: row;

    li {
      width: 1.78rem;
      height: 1.78rem;
      border: #d1d1d1 dashed 1px;
      display: flex;
      align-items: center;
      justify-content: center;

      i {
        color: #cccccc;
        font-size: 0.5rem;
      }
    }
  }
}
</style>
